package keeto.com.vn.classified.task;

import java.io.IOException;

import org.apache.http.client.ClientProtocolException;
import org.json.JSONException;

import keeto.com.vn.classified.core.ClassifiedCore;
import keeto.com.vn.classified.core.ClassifiedListener;
import keeto.com.vn.classified.network.IProtocol;
import keeto.com.vn.classified.request.UpdateUserInfoRequest;
import keeto.com.vn.classified.response.UpdateUserInfoResponse;

public class TaskUpdateUserInfo extends AbstractTask {
	String displayName;
	String phone;
	String area ;
	String gender;
	String authenKey;
	String email;
	
	public TaskUpdateUserInfo(ClassifiedListener listener, ClassifiedCore core, String displayName, String phone, String email, String gender, String area, String authenKey) {
		super(listener, core);
		// TODO Auto-generated constructor stub
		this.area=area;
		this.displayName=displayName;
		this.authenKey=authenKey;
		this.email=email;
		this.gender=gender;
		this.phone=phone;
	}

	@Override
	public void run() throws ClientProtocolException, JSONException,
			IOException {
		// TODO Auto-generated method stub
		UpdateUserInfoRequest request= new UpdateUserInfoRequest();
		request.setArea(area);
		request.setAuthenKey(authenKey);
		request.setDisplayName(displayName);
		request.setEmail(email);
		request.setGender(gender);
		request.setPhone(phone);
		UpdateUserInfoResponse response= json.finishUpdateUserInfo(request);
		for(ClassifiedListener mListener:listeners){
			mListener.finishUpdateUserProfile(response.getReturnCode());
		}
	}

	@Override
	public void timeoutCallback() {
		// TODO Auto-generated method stub
		for(ClassifiedListener mListener:listeners){
			mListener.finishUpdateUserProfile(IProtocol.STATUS_CODE_GENERICFAIL_500);
		}
	}

}
